#include<bits/stdc++.h>
#include <SDL2/SDL.h>
#include "../src/paint.hpp"
#include "../src/window.hpp"
#include "../src/image.hpp"
// #include <iostream>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <chrono>

// #include "../src/effects/2dndBlur.hpp"

extern SDL_Surface* winSurface;
extern SDL_Window* window;

using namespace std;
float fab(float y) { return y > 0 ? y : -y; }
void breseham (int x, int y, int x1, int y1) {

	if (x > x1)
	{
		x = x + x1;
		x1 = x - x1;
		x = x - x1;
		
		y = y + y1;
		y1 = y - y1;
		y = y - y1;
	}

	float k, e, dx, dy;
	dx = x1 - x;
	dy = y1 - y;

	k = dy / dx;

	if (fab(k) <= 1) {
		e = -dx;
		while (x <= x1) {
			drawPixel(x, y);
			x++;
			e += 2 * fab(dy);
			if (e >= 0) {
				dy > 0 ? y++ : y--;
				e -= 2 * dx;
			}
		}
	} else {
		e = -fab(dy);
		while (y <= y1)
		{
			drawPixel(x, y);
			y++;
			e += 2 * dx;
			if (e >= 0)
			{
				x++;
				e -= 2 * fab(dy);
			}
		}
	}
}
int main()
{
    initGraph(640,640);
	for (int y = 0; y < 200; y++) {
		breseham (200, 200, 300, y);
	}
    // getch();
	// drawLine (0, 0, 30, 4);
	// drawPixel (30, 4);
	getchar ();
    closeGraph();
}